package complex.java.zip;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class Test {
	/**
     * @param args
     * @throws UnsupportedEncodingException
     * @throws DataFormatException
     */
    public static void main(String[] args) throws UnsupportedEncodingException,
           DataFormatException {
       // TODO Auto-generated method stub
       // Encode a String into bytes
       String charzetName = "UTF-8";
       String inputString = "http://www.a.com/long.jsp?ids=123455678901234,123456978901234,123456789301234,123456778901234,123456785901234,123456788901234,123456789901234,123456278901234,123456728901234,123453678901234,123457678901234,123456789801234,123452678901234,123456789071234,123456728901234,123456078901234,123456734348901234,12345675678901234,12345613378901234,1234567128901234,1234567845901234,1234562378901234,1234567878901234,1234567867901234,1234567890132234,1234567892301234,1234567890132234,1234567892301234,1234567218901234,1234567833901234,123456789021234,123456789101234,123456784901234,123456738901234,123456789021234,123456789012934,123456789801234,123456789071234,123456789601234,123345678901234,123456785901234,123456783901234,123456789091234,123456768901234,123456788901234,123456718901234,123456768901234,123453678901234,123456783901234,123456789018234,123456788901234";
       try {
		byte[] decoder =(new BASE64Decoder()).decodeBuffer(inputString);
		String temp =new String(decoder);
		System.out.println(temp);
		
		String a = (new BASE64Encoder()).encodeBuffer(temp.getBytes());
		System.out.println(a);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
       
       System.out.println(inputString.length());
       byte[] input = inputString.getBytes(charzetName);
 
       // Compress the bytes
       byte[] output = new byte[10000];
       Deflater compresser = new Deflater();
       compresser.setInput(input);
       compresser.finish();
       int compressedDataLength = compresser.deflate(output);
 
       // decode the bytes into a String
       String deoutputString = new String(output,0,compressedDataLength,charzetName);
      
       System.out.println("compressedDataLength= " + compressedDataLength);
       // Decompress the bytes
       Inflater decompresser = new Inflater();
       decompresser.setInput(output, 0, compressedDataLength);
       byte[] result = new byte[10000];
       int resultLength = decompresser.inflate(result);
       decompresser.end();
 
       // Decode the bytes into a String
       String outputString = new String(result,0,resultLength,charzetName);
 
       System.out.println("outputString = " + outputString);
       System.out.println("resultLength=" + resultLength);
 
    }
}
